package com.microtf.inscription.web.service;

import com.microtf.inscription.framework.pojo.wechat.input.TextMessage;
import com.microtf.inscription.framework.pojo.wechat.input.event.SubscribeEvent;
import com.microtf.inscription.framework.pojo.wechat.listener.EventListener;
import com.microtf.inscription.framework.pojo.wechat.output.Message;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
@Slf4j
public class WeChatListener implements EventListener {
    @Override
    @SuppressWarnings("unchecked")
    public <T extends Message> Optional<T> onMessage(TextMessage message) {
        log.info(message.toString());
        com.microtf.inscription.framework.pojo.wechat.output.TextMessage textMessage=new com.microtf.inscription.framework.pojo.wechat.output.TextMessage();
        textMessage.setContent("hello");
        textMessage.setToUserName(message.getFromUserName());
        textMessage.setFromUserName(message.getToUserName());
        return (Optional<T>) Optional.of(textMessage);
    }

    @Override
    @SuppressWarnings("unchecked")
    public <T extends Message> Optional<T> onEvent(SubscribeEvent event) {
        com.microtf.inscription.framework.pojo.wechat.output.TextMessage textMessage=new com.microtf.inscription.framework.pojo.wechat.output.TextMessage();
        textMessage.setContent("很高兴见到您。在这里可以阅读到更多的新闻，学习到更好的工作技能。   一起来玩吧。");
        textMessage.setToUserName(event.getFromUserName());
        textMessage.setFromUserName(event.getToUserName());
        return (Optional<T>) Optional.of(textMessage);
    }
}
